cc.Class({
    extends: cc.Component,

    properties: {
        speed: {
            default: 10,
            displayName: "Bubble speed"
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
    },

    fire: function (direction) {
        var x = this.speed*(Math.sin(2*Math.PI/360*(this.player.node.rotation)));
        var y = this.speed*(Math.cos(2*Math.PI/360*(this.player.node.rotation)));
        var move;
        var action;
        // switch (direction) {
        //     case "a":
        //         move = cc.moveBy(1, cc.v2(this.speed * (-1), 0));
        //         break;
        //     case "d":
        //         move = cc.moveBy(1, cc.v2(this.speed * (1), 0));
        //         break;
        //     case "s":
        //         move = cc.moveBy(1, cc.v2(0, this.speed * (-1)));
        //         break;
        //     case "w":
        //         move = cc.moveBy(1, cc.v2(0, this.speed * (1)));
        //         break;
        // }
        move = cc.moveBy(1, cc.v2(x, y));
        var callback = cc.callFunc(this.destroyBubble, this);
        action = cc.sequence(move, callback);
        this.node.runAction(action);
    },
    destroyBubble(){
        this.node.destroy();
    },

    start() {

    },

    update (dt) {
        if(!cc.isValid(this.game.enemy)){
            return 0;
        }
        var playerPos = this.game.enemy.getPosition();
        // 根据两点位置计算两点之间距离
        var dist = this.node.position.sub(playerPos).mag();
        if(dist<=this.game.enemy.width/2){
            this.node.destroy();
            this.game.enemy.destroy();
        }
    },
});
